package com.objcat.servicea.controller;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author misheep
 * @since 2020-07-27
 */
@RestController
@RequestMapping("service-a/account")
@Slf4j
public class PowerController {
    @RequestMapping("index")
    public String index() {
        return "index";
    }

    @RequestMapping("login")
    @ResponseBody
    public Object login(HttpServletResponse response) {
        log.info("错误进入login");
        JSONObject userInfo = new JSONObject();
        userInfo.put("username", "xinyues");
        List<String> roles = new ArrayList<>();
        roles.add("Admin");
        roles.add("Dev");
        userInfo.put("roles", roles);
        response.addHeader("AccountInfo", userInfo.toJSONString());

        JSONObject result = new JSONObject();
        result.put("code", 0);
        return result;
    }
    @RequestMapping("main")
    public String toMain() {
        return "main";
    }
    @RequestMapping("getAllAccount")
    @ResponseBody
    public Object getAllAccount() {
        JSONObject userInfo = new JSONObject();
        userInfo.put("username", "xinyues");
        List<String> roles = new ArrayList<>();
        roles.add("Admin");
        roles.add("Dev");
        userInfo.put("roles", roles);
        return userInfo;
    }

    @RequestMapping("authen")
    @ResponseBody
    public String authen(HttpServletResponse response) {
        System.out.println("service-a/ssss");
        return "1";
    }

}
